package principle.DependenceInversionPrinciple.perfection;

import principle.DependenceInversionPrinciple.origon.BetUser;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author： pang-yun
 * @date： 2021-08-25 20:36
 * 功能目的 ：用于
 */

public class DrawWeight implements IDraw {
    @Override
    public List<BetUser> prize(List<BetUser> list, int count) {
        if (list.size() <= count) return list;

        // 自定义降序
        list.sort((o1, o2) -> {
            int i = o2.getUserWeight() - o1.getUserWeight();
            if (i == 0) return 0;
            return i > 0 ? 1 : -1;
        });
        // 升序
        list.sort(Comparator.comparing(BetUser::getUserWeight));

        // 利用Collections.sort 来排序
        Collections.sort(list, new Comparator<BetUser>() {
            @Override
            public int compare(BetUser o1, BetUser o2) {
                return o2.getUserWeight()-o1.getUserWeight();
            }
        });

        //创建新的集合 将前几名返回
        ArrayList<BetUser> betUsers = new ArrayList<>(count);
        list.stream().limit(count).forEach(a->betUsers.add(a));
        return betUsers;
    }
}
